package com.example.home.hospital.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.hospital.bean.RegistrationBean;

import java.util.List;

public class NormalAdapter extends RecyclerView.Adapter<NormalAdapter.MyHoldy> {

    private Context context;
    private List<RegistrationBean.RowsBean> list;
    private View view;

    public CallBack callBack;

    public interface CallBack {
        void callback(int position);
    }


    public NormalAdapter(Context context, List<RegistrationBean.RowsBean> list, CallBack callBack) {
        this.context = context;
        this.list = list;
        this.callBack = callBack;
    }

    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_normal, null);
        return new MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        holder.categoryName.setText("类型：" + list.get(position).getCategoryName());
        holder.money.setText("挂号费：" + list.get(position).getMoney());
        holder.time.setText("2020-9-21  周一  下午 14:00");


        holder.yuyue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callBack != null) {
                    Log.e("xhf","OKHttpTool");
                    callBack.callback(position);
                }

            }
        });


    }


    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        private RelativeLayout rootView;
        private ImageView img;
        private TextView categoryName;
        private TextView money;
        private TextView time;
        private Button yuyue;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            rootView = itemView.findViewById(R.id.rootView);
            img = itemView.findViewById(R.id.img);
            categoryName = itemView.findViewById(R.id.categoryName);
            money = itemView.findViewById(R.id.money);
            time = itemView.findViewById(R.id.time);
            yuyue = itemView.findViewById(R.id.yuyue);

        }
    }
}
